package cn.intertion.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * author wangchao
 * 用户注册短信验证工具类
 */
public class CommonRpc {

    public static void sendMesg(String poneNumber,String messageCode,String signName,String accessKeyId,String accessSecret){
//      accessKeyId= "LTAIW0s7TasGnY4F";
//      accessSecret= "FwK2T2SyNg1WRO4nLN6caMApfsMk9M";
//      poneNumber="17610083178";
//      messageCode="343254";
//      signName="intertion";
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", poneNumber);
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", "SMS_166376831");
        request.putQueryParameter("TemplateParam", "{\"code\":\"" +
                messageCode +
                "\"}");

        try {
            client.getCommonResponse(request);
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    //以下是阿里的demo
/*    public static void main(String[] args) {
        String accessKeyId= "LTAIW0s7TasGnY4F";
        String accessSecret= "FwK2T2SyNg1WRO4nLN6caMApfsMk9M";
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
//request.setProtocol(ProtocolType.HTTPS);
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", "17610083178");
        request.putQueryParameter("SignName", "intertion");
        request.putQueryParameter("TemplateCode", "SMS_166376831");
        request.putQueryParameter("TemplateParam", "{\"code\":\"456543\"}");

        try {
            client.getCommonResponse(request);
//            CommonResponse response = client.getCommonResponse(request);
//            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }*/


}